// 泛型函数的使用

function identity0(arg: number): number {
	return arg;
}

console.log("这种写法只可以传数字类型参数");
console.log(typeof(identity0(123)));
console.log(identity0(123));

function identity1(arg: any): any {
    return arg;
}

function identity2<T>(arg: T): T {
    return arg;
}

console.log("这种写法可以传任何类型参数,但是代码提示时,类型丢失");
console.log(typeof(identity1(123)));
console.log(identity1(123));
console.log(typeof(identity1("123")));
console.log(identity1("123"));
console.log(typeof(identity1([1,2,3])));
console.log(identity1([1,2,3]));
const a = identity1("123");


function identity3<T>(arg: T): T {
    return arg;
}

console.log("这种写法可以传任何类型参数,代码提示时类型不丢失,并且不使用尖括号时,还可推断类型");
console.log(typeof(identity3(123)));
console.log(identity3(123));
console.log(typeof(identity3("123")));
console.log(identity3("123"));
console.log(typeof(identity3([1,2,3])));
console.log(identity3([1,2,3]));
const a1 = identity3(123)
const a2 = identity3<number>(123)
const a3 = identity3("123");
const a4 = identity3<string>("123");